using System;
using System.Windows.Forms;
//using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
//using NET.Library.Web;
using System.Web;

namespace NET.Library.Windows.Forms
{
	/// <summary>
	/// '-----------------------------------------------------------------------------------------
	/// 'Class Name : Validation
	/// 'Author     : Martin Tomkins
	/// 'Synopsis   : Class for common code used in windows forms
	/// '-----------------------------------------------------------------------------------------
	/// </summary>
	public class Validation  
	{
		/// <summary>
		/// '-----------------------------------------------------------------------------------------
		/// 'Used to remove 0 from null integers in TextBoxes
		/// '-----------------------------------------------------------------------------------------
		/// </summary>
		/// <param name="Value"></param>
		/// <returns></returns>
		public static string NumCheck(int Value)
		{
			if (Value > 0)
			{
				return Value.ToString();
			}
			else
			{
				return "";
			}
		}																	   


		
		// '-----------------------------------------------------------------------------------------
		// 'Check for numeric value in TextBoxes
		// '-----------------------------------------------------------------------------------------
        //public static bool CheckNumeric(System.Web.UI.WebControls.TextBox TextBox, string Msg)
        //{
        //    if (TextBox.Text.Length > 0)
        //    {
        //        if (!IsNumeric(TextBox.Text))
        //        {
        //            return false;
        //        }
        //        else
        //        {
        //            return true;
        //        }
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="TextBox"></param>
		/// <param name="Msg"></param>
		/// <returns></returns>
		public static bool CheckNumeric(System.Windows.Forms.TextBox TextBox, string Msg)
		{
			if (TextBox.Text.Length > 0)
			{
				if (!IsNumeric(TextBox.Text))
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Value"></param>
		/// <returns></returns>
		public static bool IsNumeric(object Value)
		{
			string strPattern = "\\d";
			Match m;

			if (Value==null)
			{
				return false;
			}

			m = Regex.Match(Value.ToString(), strPattern);

			if (!m.Success) //value is numeric
			{
				return false;
			}
			return true;
			
		}

		

		


		
		// '--------------------------------------------------------------------------------------------------
		// 'Validate Web TextBox
		// '--------------------------------------------------------------------------------------------------
        //public static void ValidateTextBox(System.Web.UI.WebControls.TextBox TextBox, string Msg)
        //{
        //    if (TextBox.Text.Length < 1)
        //    {
        //        HttpContext.Current.Response.Write(JavaScript.GoBackMsg(Msg));
        //    }
        //}

		/// '--------------------------------------------------------------------------------------------------
		/// 'Validate Windows TextBox
		/// '--------------------------------------------------------------------------------------------------
		public static void ValidateTextBox(System.Windows.Forms.TextBox TextBox, string Msg)
		{
			if (TextBox.Text.Length < 1)
			{
				//HttpContext.Current.Response.Write(JavaScript.GoBackMsg(Msg));
                MessageBox.Show(Msg);
			}
		}


		/// '--------------------------------------------------------------------------------------------------
		/// 'Validate Dropdownlist
		/// '--------------------------------------------------------------------------------------------------
		public static void ValidateDropDownList(ComboBox DropDownList, string Msg)
		{
			if (DropDownList.SelectedItem.ToString().Length < 1)
			{
				//HttpContext.Current.Response.Write(JavaScript.GoBackMsg(Msg));
                MessageBox.Show(Msg);
			}
		}
	}
}
